﻿  package org.kolonitsky.alexey.flashui
{
  import flash.display.MovieClip;
  import flash.events.Event;
  import flash.events.MouseEvent;
  import flash.text.TextField;
  import flash.text.TextFieldAutoSize;

  public dynamic class Button extends MovieClip
  {
    public function Button() {
      super()
      stop()
      useHandCursor = true
      buttonMode = true
	  enabled = true;
    }

    public function addEventHandlers (): void {
      addEventListener(MouseEvent.ROLL_OVER, function ():void {gotoAndPlay("over")});
      addEventListener(MouseEvent.ROLL_OUT, function ():void {gotoAndPlay("up")});
    }

    public function removeEventHandlers (): void {
      removeEventListener(MouseEvent.ROLL_OVER, function ():void {gotoAndPlay("over")});
      removeEventListener(MouseEvent.ROLL_OUT, function ():void {gotoAndPlay("up")});
    }

    /**
     * Enabled
     * @default true
     */
    private var _enabled:Boolean;

    override public function set enabled (value:Boolean): void {
      if (_enabled == value) return
      _enabled = value
      if (_enabled) {
        addEventHandlers()
        gotoAndStop("up")
      } else {
        removeEventHandlers()
        gotoAndStop("disabled")
      }
    }

    override public function get enabled ():Boolean {
      return _enabled
    }

  }
}